from redis import Redis

class RedisCon:
    def __init__(self):
        self.conn = Redis(host='localhost',port=6379)
    
    # 存set
    def insert_set(self,key,val):
        for i in val:
            self.conn.sadd(key,i)
    # 取set
    def find_set(self,key):
        val = self.conn.smembers(key)
        if val:
            list = []
            for i in val:
                list.append(str(i,encoding='utf8'))
            return list
        else:

            return None

    
   # hash：属性型添加
   
    def insert_hash(self,key,params,value):
        self.r.hset(key,params,value)
    # 取某个属性的值
    def get_value_hash(self,key,parmas):
        return self.r.hget(key,parmas)
    # 取所有属性的值
    def get_all_hash(self,key):
        return self.r.hgetall(key)
    # 删除某个属性
    def del_hash(self,key,params):
        self.r.hdel(key,params)
        

# r = RedisCon()
# r.insert_set('name',['/asdsd','/asdasdasdasd'])
# print(r.find_set('name'))
# class RedisCon:
#     def __init__(self):
#         self.conn = Redis(host='localhost',port=6379,db=1)

#     # 存
#     def set_str(self, mobile, codes, time=0):
#         if time == 0:
#             self.conn.set(mobile, codes)
#         else:
#             self.conn.setex(mobile, time, codes)

#     # 取
#     def get_str(self, mobile):
#         value = self.conn.get(mobile)
#         if value:
#             value = str(value, encoding='utf8')
#         return value

#     # 删
#     def del_str(self, mobile):
#         self.conn.delete(mobile)

#     # 存集合
#     def insert_set(self, key, val):
#         return self.conn.sadd(key, *val)

#     # 取集合
#     def find_set(self, key):
#         val = self.conn.smembers(key)
#         if val:
#             list = []
#             for i in val:
#                 list.append(str(i, encoding='utf8'))
#             return list
#         else:
#             return None


# r = Redis()

# print(r.find_set('21031'))


# import json
rs = RedisCon()
# rs.insert_set('name',['/asdsd','/asdasdasdasd'])
# print(rs.find_set('name'))

# key = 'interface1'
# list=['/abc','/user']
# rs.insert_set(key,list)

# me = rs.find_set(key)
# print(me)
# for i in mes:
#     if '/abc' == str(i,encoding='utf8'):
# print(rs.find_set(key))
        # print(1)
# if '/abc' in json.loads(mes):
#     print(1)
# else:
#     print(2)

